//
//  TCLYOrderTableViewCell.m
//  YuErmuYing
//
//  Created by LYang on 16/8/17.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYOrderTableViewCell.h"
#import "Masonry.h"
#import "Macros.h"

@implementation TCLYOrderTableViewCell

-(instancetype) initWithReuseIdentifier:(NSString *)reuseIdentifier SerialNumber:(int) serialNumber{
    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = bgColor;
        UIView * bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor whiteColor];
        bgView.tag = 201;
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).offset(34/2.0);
            make.left.mas_equalTo(self);
            make.right.mas_equalTo(self);
            make.bottom.mas_equalTo(self);
        }];
        //展示物品图片的ImageView
        self.goodsImageView = [[UIImageView alloc] init];
        [bgView addSubview:self.goodsImageView];
        [self.goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(bgView.mas_top).offset(36);
            make.left.mas_equalTo(bgView.mas_left).offset(6);
            make.width.mas_equalTo(160/2.0);
            make.height.mas_equalTo(162/2.0);
        }];
        
        //展示物品价格的Label
        self.goodsPriceLabel = [[UILabel alloc] init];
        self.goodsPriceLabel.textColor = blackFont;
        self.goodsPriceLabel.textAlignment = NSTextAlignmentCenter;
        self.goodsPriceLabel.font = [UIFont boldSystemFontOfSize:12];
        [bgView addSubview:self.goodsPriceLabel];
        [self.goodsPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(bgView.mas_top).offset(15);
            make.right.mas_equalTo(bgView.mas_right).offset(0);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(20);
        }];
        
        if (serialNumber == 5) {
            self.discountLabel = [[UILabel alloc] init];
            self.discountLabel.textColor = btnColor;
            self.discountLabel.textAlignment = NSTextAlignmentCenter;
            self.discountLabel.font = [UIFont boldSystemFontOfSize:16];
            [bgView addSubview:self.discountLabel];
            [self.discountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(bgView.mas_top).offset(10);
                make.right.mas_equalTo(bgView.mas_right);
                make.left.mas_equalTo(self.goodsPriceLabel);
                make.height.mas_equalTo(self.goodsPriceLabel);
            }];
        }
        //显示商品数量的label
        self.goodsNumLabel = [[UILabel alloc] init];
        self.goodsNumLabel.textColor = blackFont;
        self.goodsNumLabel.textAlignment = NSTextAlignmentCenter;
        self.goodsNumLabel.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.goodsNumLabel];
        [self.goodsNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.goodsPriceLabel);
            make.top.mas_equalTo(self.goodsPriceLabel.mas_bottom).offset(110/2.0);
            make.width.mas_equalTo(self.goodsPriceLabel);
            make.height.mas_equalTo(20);
        }];
        
        //详细介绍商品信息的label
        self.goodsInstructionsLabel = [[UILabel alloc] init];
        self.goodsInstructionsLabel.textColor = blackFont;
        self.goodsInstructionsLabel.textAlignment = NSTextAlignmentLeft;
        self.goodsInstructionsLabel.numberOfLines = 0;
        self.goodsInstructionsLabel.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.goodsInstructionsLabel];
        [self.goodsInstructionsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.goodsPriceLabel);
            make.left.mas_equalTo(self.goodsImageView.mas_right).offset(6);
            make.right.mas_equalTo(self.goodsPriceLabel.mas_left).offset(-6);
            make.bottom.mas_equalTo(self.goodsNumLabel.mas_bottom).offset(45/2.0);
        }];
        
        UIImageView * imgaeView = [[UIImageView alloc] init];
        imgaeView.backgroundColor = [UIColor lightGrayColor];
        imgaeView.tag = 101;
        [bgView addSubview:imgaeView];
        [imgaeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.goodsInstructionsLabel.mas_bottom).offset(0);
            make.left.mas_equalTo(bgView);
            make.right.mas_equalTo(bgView);
            make.height.mas_equalTo(1);
        }];
        
        self.priceLabel = [[UILabel alloc] init];
        self.priceLabel.font = [UIFont boldSystemFontOfSize:16];
        self.priceLabel.textColor = [UIColor colorWithRed:239/255.0 green:25/255.0 blue:98/255.0 alpha:1];
        self.priceLabel.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:self.priceLabel];
        [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo([self viewWithTag:101].mas_bottom).offset(0);
            make.right.mas_equalTo(bgView.mas_right).offset(0);
            make.width.mas_equalTo(120);
            make.height.mas_equalTo(30);
        }];
        
        UILabel * sum = [[UILabel alloc] init];
        sum.text = @"合计:";
        sum.textColor = [UIColor blackColor];
        sum.textAlignment = NSTextAlignmentCenter;
        sum.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:sum];
        [sum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.priceLabel);
            make.right.mas_equalTo(self.priceLabel.mas_left).offset(0);
            make.width.mas_equalTo(35);
            make.height.mas_equalTo(30);
        }];
        
        self.goodsSumLabel = [[UILabel alloc] init];
        self.goodsSumLabel.textColor = grayFont;
        self.goodsSumLabel.textAlignment = NSTextAlignmentCenter;
        self.goodsSumLabel.font = [UIFont systemFontOfSize:12];
        [bgView addSubview:self.goodsSumLabel];
        [self.goodsSumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(sum);
            make.right.mas_equalTo(sum.mas_left).offset(0);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(sum);
        }];
        UIImageView * imageView1 = [[UIImageView alloc] init];
        imageView1.backgroundColor = [UIColor lightGrayColor];
        imageView1.tag = 102;
        [bgView addSubview:imageView1];
        [imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.goodsSumLabel.mas_bottom).offset(0);
            make.left.mas_equalTo(bgView);
            make.right.mas_equalTo(bgView);
            make.height.mas_equalTo(1);
        }];
        switch (serialNumber) {
            case 1:
                [self createPay];
                break;
            case 2:
                [self createDelivery];
                break;
            case 3:
                [self createGoods];
                break;
            case 4:
                [self createEvaluation];
                break;
            case 5:
                [self createPublished];
                break;
        }
    }
    return self;
}
//代付款
-(void) createPay{
    UIView * bgView = [self viewWithTag:201];
    self.payBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.payBtn setTitle:@"付款" forState:UIControlStateNormal];
    [self.payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.payBtn.backgroundColor = btnColor;
    [bgView addSubview:self.payBtn];
    [self.payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([self viewWithTag:102].mas_bottom).offset(0);
        make.right.mas_equalTo(bgView);
        make.height.mas_equalTo(64/2.0);
        make.width.mas_equalTo(171/2.0);
    }];

}
-(void)createDelivery{
    UIView * bgView = [self viewWithTag:201];
    
    self.deliveryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.deliveryBtn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [self.deliveryBtn setTitle:@"提醒发货" forState:UIControlStateNormal];
    [self.deliveryBtn setTitle:@"已经提醒" forState:UIControlStateSelected];
    
    [self.deliveryBtn setTitleColor:btnColor forState:UIControlStateNormal];
    self.deliveryBtn.layer.borderColor = [UIColor colorWithRed:239/255.0 green:25/255.0 blue:98/255.0 alpha:1].CGColor;
    self.deliveryBtn.layer.borderWidth = 1;
    
    [bgView addSubview:self.deliveryBtn];
    [self.deliveryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([self viewWithTag:102].mas_bottom).offset(0);
        make.right.mas_equalTo(bgView);
        make.height.mas_equalTo(64/2.0);
        make.width.mas_equalTo(171/2.0);
    }];
    
    self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.cancelBtn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [self.cancelBtn setTitleColor:[UIColor colorWithRed:239/255.0 green:25/255.0 blue:98/255.0 alpha:1] forState:UIControlStateNormal];
    [self.cancelBtn setTitle:@"取消订单" forState:UIControlStateNormal];
    
    self.cancelBtn.layer.borderColor = [UIColor colorWithRed:239/255.0 green:25/255.0 blue:98/255.0 alpha:1].CGColor;
    self.cancelBtn.layer.borderWidth = 1;
    
    [bgView addSubview:self.cancelBtn];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.deliveryBtn);
        make.right.mas_equalTo(self.deliveryBtn.mas_left).offset(-10);
        make.width.mas_equalTo(self.deliveryBtn);
        make.height.mas_equalTo(self.deliveryBtn);
    }];
}

-(void) createGoods{
    UIView * bgView = [self viewWithTag:201];
    
    self.goodsBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.goodsBtn setTitle:@"确认收货" forState:UIControlStateNormal];
    [self.goodsBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.goodsBtn.backgroundColor = btnColor;
    [bgView addSubview:self.goodsBtn];
    [self.goodsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([self viewWithTag:102].mas_bottom).offset(0);
        make.right.mas_equalTo(bgView);
        make.height.mas_equalTo(64/2.0);
        make.width.mas_equalTo(171/2.0);
    }];
}
-(void)createEvaluation{
    UIView * bgView = [self viewWithTag:201];
    
    self.evaluationBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.evaluationBtn setTitle:@"评价" forState:UIControlStateNormal];
    [self.evaluationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.evaluationBtn.backgroundColor = btnColor;
    [bgView addSubview:self.evaluationBtn];
    [self.evaluationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([self viewWithTag:102].mas_bottom).offset(0);
        make.right.mas_equalTo(bgView);
        make.height.mas_equalTo(64/2.0);
        make.width.mas_equalTo(171/2.0);
    }];
}
-(void)createPublished{
    UIView * bgView = [self viewWithTag:201];
    
    self.publishedBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.publishedBtn setTitle:@"晒单" forState:UIControlStateNormal];
    [self.publishedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.publishedBtn.backgroundColor = btnColor;
    [bgView addSubview:self.publishedBtn];
    [self.publishedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([self viewWithTag:102].mas_bottom).offset(0);
        make.right.mas_equalTo(bgView);
        make.height.mas_equalTo(64/2.0);
        make.width.mas_equalTo(171/2.0);
    }];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
